<template>
    <header>
        <h2>记事本</h2>
        <div class="body">
            <input v-focus @keyup.enter="add" v-model="newName" placeholder="请输入任务">
            <button @click="add">添加任务</button>
        </div>
    </header>
</template>

<script>
export default {
    data(){
        return{
            newName: ''
        }
    },
    methods:{
        add(){
            console.log(this.newName)
            this.$emit('AddName',this.newName)
            this.newName = ''
        }
    },
    directives:{
        // 指令名
        focus:{
        // 生命周期钩子-inserted:在相应元素插入后生效
            inserted(el){
            // el:对应元素
            // binding:传值
                el.focus()
            }
        }
    }
}
</script>

<style scoped>
    h2{
        color: red;
    }
    .body{
        /* width: 400px; */
        padding: 10px;
        background-color: #ffa;
        display: flex;
        justify-content: space-between;
    }
    input,button{
        height: 50px;
    }
</style>